package com.ildepinc.persistence.concretes.models;

import java.util.HashMap;

import com.ildepinc.persistence.abstracts.TableGeneric;
import com.ildepinc.persistence.enums.NewProgressiveMethod;
// You should customize this class
// depending on the database engine
// you want to use.
// This version is for Apache Derby
public class Catalog extends TableGeneric {

  // CREATE TABLE DEVSCHEMA.CATALOGS (
  //   ID INT NOT NULL,
  //   NAME VARCHAR(25) NOT NULL,
  //   DESCRIPTION VARCHAR(250) NOT NULL,
  //   CONSTRAINT CATALOGS_PK PRIMARY KEY (ID)
  // );

  private Long id;
  private String name;
  private String description;

  public Catalog() {
    this.clear();
  }

  public Catalog(Long id, String name, String description, String schema) {
    this.clear();
    this.setDefaults(schema);
    this.id = id;
    this.name = name;
    this.description = description;
  }

  public Catalog(String schema) {
    this.clear();
    this.setDefaults(schema);
  }

  public String getDescription() {
    return description;
  }

  public Long getId() {
    return id;
  }

  public String getName() {
    return name;
  }

  public void setDescription(String description) {
    this.description = description;
  }

  public void setId(Long id) {
    this.id = id;
  }

  public void setName(String name) {
    this.name = name;
  }

  @Override
  public void setDefaults(String schema) {
    this.setSchema(schema);
    this.setTableName("CATALOGS");
    String fullQualifiedName = this.getSchema() + "." + this.getTableName();
    this.setPrimaryKeys(new HashMap<String, Object>() {
      {
        put("ID", null);
      }
    });
    this.setPkSingleColumn(Boolean.valueOf(true));
    this.setPkAutoIncremental(Boolean.valueOf(false));
    this.setSqlCreateTable("CREATE TABLE " + fullQualifiedName
        + " ( ID INT NOT NULL, NAME VARCHAR(25)," + " DESCRIPTION VARCHAR(250) NOT NULL,"
        + " CONSTRAINT CATALOGS_PK PRIMARY KEY (ID)"
        + " )");
    this.setSqlInsert("INSERT INTO " + fullQualifiedName
      + " ( ID, NAME, DESCRIPTION )"
      + " VALUES ( ?, ?, ? )");
    this.setSqlUpdate("UPDATE " + fullQualifiedName
      + " SET NAME = ?, DESCRIPTION = ?");
    this.setSqlSelect("SELECT * FROM " + fullQualifiedName);
    this.setSqlDelete("DELETE FROM " + fullQualifiedName);
    this.setNewProgressiveMethod(NewProgressiveMethod.FIRST_AVAILABLE);
  }

  @Override
  public void clear() {
    super.clear();
    this.id = null;
    this.name = null;
    this.description = null;
  }

}
